<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :md="6" :sm="8">
            <a-form-item label="名称">
              <a-input placeholder="请输入名称" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="标识key">
              <a-input placeholder="请输入标识key" v-model="queryParam.key"></a-input>
            </a-form-item>
          </a-col>
          <!--<a-col :md="6" :sm="8">
            <a-form-item label="name">
              <a-input placeholder="请输入name" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
        <template v-if="toggleSearchStatus">
        <a-col :md="6" :sm="8">
            <a-form-item label="key">
              <a-input placeholder="请输入key" v-model="queryParam.key"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="category">
              <a-input placeholder="请输入category" v-model="queryParam.category"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="createTime">
              <a-input placeholder="请输入createTime" v-model="queryParam.createTime"></a-input>
            </a-form-item>
          </a-col>
          </template>-->
          <a-col :md="6" :sm="8" >
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!--<a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>-->
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>
    <!--<div  v-if="addModel">
    <iframe  :src="modelSrc" style="width: 100%;height: 500px" >
    </iframe>
    </div>-->
    <!-- 操作按钮区域 -->
    <!--<div class="table-operator">-->
      <!--<a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>-->
      <!--&lt;!&ndash;<a-button type="primary" icon="download" @click="handleExportXls('模型管理')">导出</a-button>-->
      <!--<a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">-->
        <!--<a-button type="primary" icon="import">导入</a-button>-->
      <!--</a-upload>&ndash;&gt;-->
      <!--<a-dropdown v-if="selectedRowKeys.length > 0">-->
        <!--<a-menu slot="overlay">-->
          <!--<a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>-->
        <!--</a-menu>-->
        <!--<a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>-->
      <!--</a-dropdown>-->
    <!--</div>-->

    <!-- table区域-begin -->
    <div>
      <!-- <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div> -->

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange">

        <span slot="name" slot-scope="text, record,index">
          {{ text }}
          <a-popover>
            <template slot="content">
              <img :src="'data:image/png;base64,'+record.base64" alt="">
            </template>
            <a-icon type="question-circle" style="color: orange;font-size:18px "/>
          </a-popover>
        </span>

        <span slot="action" slot-scope="text, record">
          <!--<a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />-->
          <!--<a @click="editModel(record)">模板</a>

          <a-divider type="vertical" />
          <a @click="deployModel(record)">发布</a>

          <a-divider type="vertical" />-->
          <!--<a @click="handleDelete(record.id)">删除</a>-->
          <a @click="pause(record)" v-text="record.suspensionState == 1?'挂起':'激活'"></a>

          <!--<a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>-->
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <model-modal ref="modalForm" @ok="modalFormOk"></model-modal>
    <!--<model-edit-modal ref="modalEditForm"></model-edit-modal>-->
  </a-card>
</template>

<script>
  import ModelModal from './modules/ModelModal'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { getAction,deleteAction,putAction,postAction} from '@/api/manage'
  import moment from "moment"
  export default {
    name: "ProcdefList",
    mixins:[JeecgListMixin],
    components: {
      ModelModal,
      /*ModelEditModal*/
    },
    data () {
      return {
        description: '流程管理管理页面',
        // 表头
        columns: [
          // {
          //   title: '#',
          //   dataIndex: '',
          //   key:'rowIndex',
          //   width:60,
          //   align:"center",
          //   customRender:function (t,r,index) {
          //     return parseInt(index)+1;
          //   }
          //  },

		   /*{
            title: '模型ID',
            align:"center",
            dataIndex: 'id'
           },*/
          {
            title: '部署ID',
            align:"center",
            dataIndex: 'deploymentId'
          },
		   {
            title: '名称',
            align:"center",
            dataIndex: 'name',
            scopedSlots: { customRender: 'name' },
           },
          {
            title: '标识',
            align:"center",
            dataIndex: 'key'
          },
          {
            title: '版本',
            align:"center",
            dataIndex: 'version'
          },
          {
            title: '部署时间',
            align:"center",
            dataIndex: 'deployTime',
            customRender: (text, row, index) => {
              if (text != ''){
                return moment(text).format("YYYY-MM-DD HH:mm");
              }
            },
            sorter: true
          },
          {
            title: '状态',
            align:"center",
            dataIndex: 'suspensionState',
            customRender:function (t,r,index) {
              let status = ''
              if (r.suspensionState == 1) {
                status = '运行'
              } else if (r.suspensionState == 2) {
                status = '暂停'
              } else {
                status = '未知'
              }
              return status;
            }
          },
		   /*{
            title: '模型分类',
            align:"center",
            dataIndex: 'category'
           },*/

          /*{
            title: '模型描述',
            align:"center",
            dataIndex: 'description'
          },*/
		   /*{
            title: 'createTime',
            align:"center",
            dataIndex: 'createTime'
           },*/
		   /*{
            title: 'lastUpdateTime',
            align:"center",
            dataIndex: 'lastUpdateTime'
           },
		   {
            title: 'version',
            align:"center",
            dataIndex: 'version'
           },
		   {
            title: 'metaInfo',
            align:"center",
            dataIndex: 'metaInfo'
           },
		   {
            title: 'deploymentId',
            align:"center",
            dataIndex: 'deploymentId'
           },
		   {
            title: 'editorSourceValueId',
            align:"center",
            dataIndex: 'editorSourceValueId'
           },
		   {
            title: 'editorSourceExtraValueId',
            align:"center",
            dataIndex: 'editorSourceExtraValueId'
           },
		   {
            title: 'tenantId',
            align:"center",
            dataIndex: 'tenantId'
           },*/
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          }
        ],
		url: {
          list: "/act/procdef/list",
          delete: "/act/model/delete",
          deleteBatch: "/act/model/deleteBatch",
          exportXlsUrl: "model/model/exportXls",
          importExcelUrl: "model/model/importExcel",
       },
        addModel:true,
        modelSrc:'',
    }
  },
  computed: {
    importExcelUrl: function(){
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
    methods: {
      editModel(row){
        /*this.modelSrc=window._CONFIG['domianURL']+'/modeler.html?modelId='+row.id;
        this.addModel=true;*/
        let url =window._CONFIG['domianURL']+'/modeler.html?modelId='+row.id;
        window.open(url);
      },
      deployModel(row){
        const that = this;

        this.$confirm({
          title: "提示",
          content: "请确认点击了左上角的保存按钮?",
          onOk: function () {
            that.loading = true;
            getAction("/act/model/deploy/",{id:row.id}).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
              }else{
                that.$message.warning(res.message)
              }
            });
          }
        });
      },

      pause(record) {
        console.log(record.id);
        let status = 1;
        if(record.suspensionState==1){
          status = 2;
        }
        let that = this;
        let url = '/act/procdef/status';
        console.log(url);
        
        this.$confirm({
          title: '提示',
          content: '确认要挂起流程?',
          onOk: function() {
            that.loading = true;
            postAction(url,
              {
                id:record.id,
                state:status
              }).then(res => {

                // setTimeout(function (){
                  if (res.success) {
                    if(status==1){
                      that.$message.success('挂起成功！')
                    }else{
                      that.$message.success('激活成功！')
                    }
                    
                    that.loadData()
                  }
                // }, 5000)
            })
          }
        })
        
      }


    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>